package org.example.atry.myservlet;

import jakarta.servlet.GenericServlet;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.example.atry.pqdao.xiudao;
import org.json.JSONObject;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/deletdata")
public class deletdata extends GenericServlet {
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        // 设置允许跨域的头部信息
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
        response.setHeader("Access-Control-Allow-Headers", "Content-Type");
        response.setHeader("Access-Control-Max-Age", "3600");
        String name = request.getParameter("na");

        xiudao xd=new xiudao();
        Integer cs=xd.delete(name);

        JSONObject json=new JSONObject();
        json.put("cs", cs);
        PrintWriter out=response.getWriter();
        out.println(json.toString());
        out.flush();

    }
}
